package com.medical_system.dao.impl;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.medical_system.dao.SickMapDaoA;
import com.medical_system.entity.DoctorA;
import com.medical_system.entity.SickA;
import com.medical_system.entity.SickMapA;
import com.medical_system.util.JDBCUtil;


public class SickMapDaoAImpl implements SickMapDaoA {
	JDBCUtil util = JDBCUtil.getInit();

	@Override
	public List<SickMapA> queryByID(int id) {
		ResultSet rs = util.query("SELECT * from sickmap where sick_id=?", id);
		List<SickMapA> list=new ArrayList<SickMapA>();
		try {
			while(rs.next()) {
				SickMapA s = new SickMapA();
				s.setBed_id(rs.getInt("bed_id"));
				s.setCktime(String.valueOf("sickmap_cktime"));
				DoctorDaoAImpl di=new DoctorDaoAImpl();
				DoctorA d=new DoctorA();
				d=di.queryByID(rs.getInt("doctor_id"));
				s.setDoctor(d);
				s.setDoctor_set(rs.getString("doctor_set"));
				s.setJstime(String.valueOf("sickmap_jstime"));
				SickDaoAImpl si=new SickDaoAImpl();
				SickA sy=new SickA();
				sy=si.queryByID(rs.getInt("sick_id"));
				s.setSick(sy);
				s.setSickmap_id(rs.getInt("sickmap_id"));
				s.setSickmap_sick(rs.getString("sickmap_sick"));
				list.add(s);
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			util.closeAll();
		}

		return list;
	}

	@Override
	public List<SickMapA> query(String id,String name,String zzys) {
		String sql="SELECT * from sickmap s INNER JOIN sick s1 ON s1.sick_id=s.sick_id INNER JOIN doctor d where d.doctor_id=s.doctor_id";
		List<SickMapA> list=new ArrayList<SickMapA>();
		if (!"".equals(id)) {
			sql += " and sickmap_id=" + id + " ";
		}
		if (!"".equals(name)) {
			sql += " and sick_name='" + name + "' ";
		}
		if (!"".equals(zzys)) {
			sql += " and doctor_name ='" + zzys + "' ";
		}
		sql+=" order by sickmap_id desc";
		ResultSet rs = util.query(sql);
		try {
			while(rs.next()) {
				SickMapA s = new SickMapA();
				s.setBed_id(rs.getInt("bed_id"));
				s.setCktime(String.valueOf("sickmap_cktime"));
				DoctorDaoAImpl di=new DoctorDaoAImpl();
				DoctorA d=new DoctorA();
				d=di.queryByID(rs.getInt("doctor_id"));
				s.setDoctor(d);
				s.setDoctor_set(rs.getString("doctor_set"));
				s.setJstime(String.valueOf("sickmap_jstime"));
				SickDaoAImpl si=new SickDaoAImpl();
				SickA sy=new SickA();
				sy=si.queryByID(rs.getInt("sick_id"));
				s.setSick(sy);
				s.setSickmap_id(rs.getInt("sickmap_id"));
				s.setSickmap_sick(rs.getString("sickmap_sick"));
				list.add(s);
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			util.closeAll();
		}

		return list;
	}
}
